const int B = 600;
void solve()
{
  int n;
  cin >> n;

  vi a(n + 1);
  rep(i, 1, n) {
    cin >> a[i];
  }

  int q;
  cin >> q;
  vl ans(q + 1);
  vector<vector<pii>> Q(B);
  rep(i, 1, q) {
    int t, k;
    cin >> t >> k;
    if (k < B) {
      Q[k].pb({t, i});
    } else {
      ll s = 0;
      REP(j, t, n, k) {
        s += a[j];
      }
      ans[i] = s;
    }
  }

  vvl sum(B);
  rep(i, 1, B - 1) {
    if (!sz(Q[i])) {
      continue;
    }
    rep(j, 0, i) {
      sum[j].clear();
      sum[j].pb(0ll);
    }
    rep(j, 1, n) {
      int z = j % i;
      sum[z].pb(sum[z].back() + a[j]);
    }

    for (auto &[t, id] : Q[i]) {
      int p = t % i, l = (t + i - 1) / i; 
      ans[id] = sum[p].back() - sum[p][l - 1];
    }
  }

  rep(i, 1, q) {
    cout << ans[i] << '\n';
  }
}